package com.archgeek.calcite.test;

import cn.hutool.core.io.resource.ResourceUtil;
import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;

import java.util.List;

/**
 * @author pizhihui
 * @date 2022-08-15 17:25
 */
public class DruidDemo {


    public static void main(String[] args) {

        String sql10 = //"create table t1 as " +
                "select t1.*,t2.* from\n" +
                "(\n" +
                "  select distinct factivity_channel,fuid\n" +
                "  from lx_dwd.dwd_maiya_invite_activity_user_channel_detail \n" +
                "  where cast(fbind_time as date)>='2022-04-14'\n" +
                "  and fuid in \n" +
                " (\n" +
                "   select distinct fuid  from dp_xxhf_mart.t_maiya_order_detail\n" +
                "   where  date(fcreate_time) between '2022-04-23' and '2022-04-23'\n" +
                "   and forder_state>=360\n" +
                "   and (fuid < 3000000 or fuid > 5000000) \n" +
                "   and fmaiya_order_plat_source=2\n" +
                " )\n" +
                ") t1\n" +
                "left join dp_fksx_mart.north_maiya_rcorder_id_total_out t2\n" +
                "on t2.fuid=t1.fuid\n" +
                "--limit 10";

        String sql2 = "create table t_order_detail(\n" +
                "        body ROW(\n" +
                "                Forder_id string,\n" +
                "                Fsku_id string,\n" +
                "                Factual_year_ratio string,\n" +
                "                Fday_ratio string,\n" +
                "                Fcreate_time string,\n" +
                "                Fmodify_time string,\n" +
                "                Fuid string,\n" +
                "                Famount string,\n" +
                "                Fversion string,\n" +
                "                Fextend_info string\n" +
                "        ),\n" +
                "\n" +
                "        headers ROW(\n" +
                "                FexecTime string,\n" +
                "                FtableName string\n" +
                "        ),\n" +
                "        mapstr as strJsonToMap(body.Fextend_info),\n" +
                "        FeventTime as TO_TIMESTAMP(body.Fcreate_time, 'yyyy-MM-dd HH:mm:ss'),\n" +
                "        FprocTime as PROCTIME()\n" +
                ") with (\n" +
                "        'connector' = 'kafka',\n" +
                "        'topic' = 'C1_JG_OTTER_order_detail_--_--_db.t_order_detail_info_-_topic',\n" +
                "        'scan.startup.mode' = 'earliest-offset',\n" +
                "        'kafka.cluster' = 'kfksrv-01',\n" +
                "        'properties.group.id' = 'qll_order_detail_v1',\n" +
                "        'format' = 'json',\n" +
                "        'json.ignore-parse-errors' = 'true'\n" +
                ")";


        String sql = ResourceUtil.readUtf8Str("1.sql");

//
        SQLStatement sqlStatements = SQLUtils.parseSingleStatement(sql, DbType.hive);
//
        System.out.println(sqlStatements.getChildren());





    }



}
